﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyChaseState : IEnemyState
{
    public EnemyChaseState(EnemyFSMSystem fsm, Character character) : base(fsm, character)
    {
    }
    private Vector3 soldierBasePosition;
    public override void DoBeforeEntering()
    {
        soldierBasePosition = GameFacade.Instance.GetSoldierCampPosition;
    }
    public override void Act(List<Character> targets)
    {
        if(targets !=null && targets.Count > 0)
        {
            m_character.MoveTo(targets[0].Position);
        }
        else
        {
            m_character.MoveTo(soldierBasePosition);
        }
    }

    public override void Reason(List<Character> targets)
    {
        if (targets == null || targets.Count == 0) return;
        float distance = Vector3.Distance(targets[0].Position, m_character.Position);
        if (distance <= m_character.AttackRange)
        {
            m_fsm.PerformTransition(EnemyTransition.CanAttack);
            return;
        }
    }
}
